define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'contents/zidian/index/ids/' + Config.ids,
					add_url: 'contents/zidian/add/cid/'+Config.ids,
					edit_url: 'contents/zidian/edit',
					del_url: 'contents/zidian/del',
					info_url: 'contents/zidian/index',
                    table: 'zidian',
                }
            });

            var table = $("#table");

            // 初始化表格f
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true},
                        {field: 'title', title: '名称'},
                        {field: 'fname', title: 'name'},
                        {field: 'porder', title: '排序'},
						{field: 'count', title: '选项个数'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter:function(value,row,index){
							var that=$.extend({},this);
							var table=$(that.table).clone(true);
							if(row.cid<1){
								$(table).data('operate-del',null);
							}else{
								$(table).data('operate-info',null);
							}
							that.table=table;
							return Table.api.formatter.operate.call(that,value,row,index);
						}
						}
                    ]
                ],
                pagination: false,
				smartDisplay:false,
				trimOnSearch:false,
				checkboxHeader:false,
				sortable:false,
				silentSort:false,
                search: false,
				trimOnSearch:false,
                commonSearch: false,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});